package crivia.ecp.carry.em;

import crivia.ecp.carry.html.X;
import crivia.ecp.carry.html.table.TDCell;
import crivia.ecp.carry.html.table.Table;
import crivia.ecp.exception.WrongDocumentObject;

public class ListTable extends AbilityTable {

	public ListTable() {
		super(Type.ListStyle);
		setCutLongWord(true);
	}

	public ListTable(Table table) {
		super(Type.ListStyle , table);
		setCutLongWord(true);
	}
	
	private int headRange = 1;
	public int getHeadRange() {
		return headRange;
	}
	public void setHeadRange(int headRange) {
		this.headRange = headRange;
	}
	
	@Override
	protected void innerStyle(StringBuilder tStr) {
		rowSpan();
		for (int k = 0; k < getRows().size(); k++){
			getRow(k).toString();
			if (k < headRange){
				StringBuilder headString = new StringBuilder();
				for (TDCell cell : getRow(k).getCells()){
					if (cell.getRowSpan() > 1 && k + 1 == headRange){
						throw new WrongDocumentObject("Can Not Row Span At Last Head . ");
					}
					headString.append(new X("th", cell.getInner())
						.setAttrs(cell.getAttrs()).setStyleMap(cell.getStyleMap())
						.addStyle("height", "38px"));
				}
				tStr.append(new X("tr", headString)
					.setAttrs(getRow(k).getAttrs()).setStyleMap(getRow(k).getStyleMap())
					.setCssClass(Style_Row_ListHead).addStyle("height", "38px"));
				continue;
			} else if ((k + headRange) % 2 == 0){
				getRow(k).setCssClass(Style_Row_ListLight).addStyle("height", "38px");
			} else {
				getRow(k).setCssClass(Style_Row_ListDark).addStyle("height", "38px");
			}
			tStr.append(getRow(k));
		}
	}
	@Override
	protected void ownStyle() {
		setCellSpacing(1);
		if (isCutLongWord()){
			addStyle("table-layout", "fixed");
		}
	}

}
